'use strict';
const db = uniCloud.database();
exports.main = async (event, context) => {
	//event为客户端上传的参数
	const resData = await db.collection("account").where({
		_id: event.id
	}).get()

	let userlist = []
	for (let i = 0; i < resData.data[0].userIds.length; i++) {
		let a = await db.collection("user").where({
			_id: resData.data[0].userIds[i]
		}).get()
		let b = await db.collection("bill").where({
			founderId: resData.data[0].userIds[i],
			accID: event.id
		}).get()
		let totalMoney = 0
		for (let j = 0; j < b.data.length; j++) {
			totalMoney += Number(b.data[j].money)
		}
		userlist.push(a.data[0])
		userlist[i].totalMoney = totalMoney.toFixed(2)
	}



	// const userlist = await db.collection("user").where({
	// 	_id: resData.data[0].userIds[0]
	// }).get()

	let data = {
		acc: resData.data[0],
		userlist: userlist
	}
	// console.log(userlist, resData.data[0].userIds);
	//返回数据给客户端
	return {
		code: 200,
		data: data
	}
};